<?php

require_once(WSB_XTENSION_PATH . 'contact/models/DbTable/Table.php');

class Contact_IndexController extends WSB_Xtension_Content
{

	public function indexAction()
	{

		$table = $this->getTable();
		$where = $table->getAdapter()->quoteInto('id=?', $this->_container->item_id);
		$row = $table->fetchRow($where);
		if($row instanceof WSB_Db_Row) {

			$configArray = $row->getConfigArray();
			$configArray['action'] = $_SERVER['REQUEST_URI'];
			$configArray['method'] = 'post';

			$config = new Zend_Config($configArray);

			$form = new Zend_Form($config);

			if($this->getRequest()->isPost() && $form->isValid($_POST)) {
				$this->addContent('Form was sent');
				$this->addContent('<ul><li>'.implode('</li><li>',$form->getValues()).'</li></ul>');
			} else {
				$this->_view->form = $form;
				$this->addContent($this->_view->render('index.phtml'));
			}
		}

	}

	public function getTable()
	{
		return new Contact_Model_DbTable_Table();
	}

}
